<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <!-- 比较含退格的字符串 -->
    <script>
      var backspace = function (s, t) {
        const build = str => {
          let res = []
          for (let a of str) {
            // 如果为退格键就出栈，否则就出栈
            res[a == '#' ? 'pop' : 'push'](a)
          }
          //返回字符串
          return res.join('')
        }
        // 比较经过处理后的俩字符串 s 及 t 是否相同
        return build(s) == build(t)
      }
      console.log(backspace('ab#c', 'ad#c'))
    </script>
  </body>
</html>
